var express = require('express');
var router = express.Router();
const { commodityModel,brandModel, categoryModel ,varietyModel} = require('../model/gjl_model')


// 获取品牌数据
router.get("/getBrandData", async (req, res, err) => {
    let brandData = await brandModel.find()
    res.send({
        code: 200,
        msg: "获取数据成功",
        brandData
    })
})

// 获取商品分类数据
router.get("/getCategoryData", async (req, res, err) => {
    let CategoryData = await categoryModel.find()
    res.send({
        code: 200,
        msg: "获取数据成功",
        CategoryData
    })
})
// 获取品种数据
router.get("/getVariety", async (req, res, err) => {
    let varietyData = await varietyModel.find()
    res.send({
        code: 200,
        msg: "获取数据成功",
        varietyData
    })
})
// 商城首页
router.get("/getData", async (req, res, err) => {
    let zl= await commodityModel.find({category_id:"6486c8999f5f2ddf93a9d4b7"}).limit(4).populate('brand_id').populate('variety_id').populate('category_id')
    let ls= await commodityModel.find({category_id:"6486c8999f5f2ddf93a9d4b8"}).limit(4).populate('brand_id').populate('variety_id').populate('category_id')
    let yp= await commodityModel.find({category_id:"6486c8999f5f2ddf93a9d4ba"}).limit(4).populate('brand_id').populate('variety_id').populate('category_id')
    let bjp= await commodityModel.find({category_id:"6486c8999f5f2ddf93a9d4b9"}).limit(4).populate('brand_id').populate('variety_id').populate('category_id')
    res.send({
        code: 200,
        msg: "获取数据成功",
        zl,
        ls,
        yp,
        bjp
    })
})
// 商品外键查询
router.get('/getGoods', async(req,res)=>{
    let list = await commodityModel.find().populate('brand_id').populate('variety_id').populate('category_id').lean()
    res.send({
        code:200,
        list
    })
})
// 抛出router
module.exports = router;